Skip to content

fix(batchquery): purge prepared query cache on compiler swap#451

Open
disaverio wants to merge 1 commit into
open-policy-agent:mainfrom
disaverio:fix/batchquery-stale-cache
Open

fix(batchquery): purge prepared query cache on compiler swap#451
disaverio wants to merge 1 commit into
open-policy-agent:mainfrom
disaverio:fix/batchquery-stale-cache

Conversation

@disaverio

@disaverio disaverio commented Jun 2, 2026

Copy link
Copy Markdown

🔩 What code changed, and why?

The BatchQueryHandler was serving stale results after policy updates because its internal preparedEvalQueryCache was not being invalidated. I have registered a compiler trigger via Manager.RegisterCompilerTrigger that purges this cache whenever the compiler is swapped (policy update via bundle plugin, opal-client sync, or direct PUT /v1/policies/...), ensuring that subsequent batch queries are evaluated against the latest version of the policies.

👍 Definition of done

  • Registered onCompilerChange trigger on the plugins manager.
  • Verified that preparedEvalQueryCache is purged when a policy change occurs.
  • Added and passed a regression test: TestBatchDataCacheInvalidationOnPolicyChange.

👟 How to test

Run the regression test specifically:
go test -v ./pkg/batchquery -run TestBatchDataCacheInvalidationOnPolicyChange

Without this change, the test fails with expected 2 (after policy update), got 1.

⛓️ Related Resources

Resolves #450

Signed-off-by: Andrea DiSaverio <disaverio.andrea@gmail.com>
@disaverio disaverio force-pushed the fix/batchquery-stale-cache branch from 240e95e to 8dc8c8e Compare June 2, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Batch Data API (/v1/batch/data/...) serves stale results after policy updates: prepared-query cache is never invalidated

1 participant